package main

import (
	"fmt"
	"strings"
)

const (
	PARTITION = "salmon.database.partition"
	DATABASE  = "database"
	USERNAME  = "username"
	PASSWORD  = "password"
	MAPPING   = "mapping"
	TABLE     = "table"
)

func main() {

	var database = getConfigBypre(PARTITION, DATABASE)
	var username = getConfigBypre(PARTITION, USERNAME)
	var password = getConfigBypre(PARTITION, PASSWORD)
	var mapping = getConfigBypre(PARTITION, MAPPING)
	var table = getConfigBypre(PARTITION, TABLE)

	fmt.Println(database)
	fmt.Println(username)
	fmt.Println(password)
	fmt.Println(mapping)
	fmt.Println(table)

	dbs := strings.Split(mapping, ",")
	for _, db := range dbs {
		temp := strings.Split(db, ">")
		var ipPortStr = temp[1]
		var dbId = temp[0]
		var ipPort = strings.Split(ipPortStr, ":")
		var con = Database{ipPort[0], ipPort[1], database, username, password, dbId}
		fmt.Println(getUrl(&con))

		setCache(dbId, con)
		data, found := getCache(dbId)
		if found {
			fmt.Println(data)
		}

	}

	tables := strings.Split(table, ";")
	for _, tabStr := range tables {
		var firstSplitStr = strings.Split(tabStr, "(")
		var tableRulerStr = strings.Split(strings.Split(firstSplitStr[1], ")")[0], ",")
		var tabRuler = TableRuler{strings.Trim(firstSplitStr[0], " "), strings.Trim(tableRulerStr[0], " "), strings.Trim(tableRulerStr[1], " "), strings.Trim(tableRulerStr[2], " "), strings.Trim(tableRulerStr[3], " "), strings.Trim(tableRulerStr[4], " ")}
		fmt.Println(tabRuler)

		setCacheTable(tabRuler.table, tabRuler)
		data, found := getCacheTable(tabRuler.table)
		if found {
			fmt.Println(data)
		}
	}

}
